<?php

namespace Yolo\Service;

use Swoole\Http\Response;

/**
 * Rpc Response
 * @author <LUSHAOMING> <lushaoming6@gmail.com>
 * @date 2024-12-04
 */
class RpcResponse
{
    protected Response $swooleResponse;

    protected int $statusCode = 200;

    protected array $headers = [];

    protected ?string $body = null;

    public function __construct(Response $swooleResponse)
    {
        $this->swooleResponse = $swooleResponse;
    }

    public function getSwooleResponse(): Response
    {
        return $this->swooleResponse;
    }

    /**
     * Set status code
     * @param int $statusCode
     * @return void
     */
    public function setStatusCode(int $statusCode): void
    {
        $this->statusCode = $statusCode;
    }

    /**
     * Get status code
     * @return int
     */
    public function getStatusCode(): int
    {
        return $this->statusCode;
    }

    /**
     * Set header
     * @param string $name
     * @param string $value
     * @return void
     */
    public function setHeader(string $name, string $value): void
    {
        $this->headers[$name] = $value;
    }

    /**
     * Get headers
     * @return array
     */
    public function getHeaders(): array
    {
        return $this->headers;
    }

    /**
     * Set body
     * @param string $body
     * @return void
     */
    public function setBody(string $body): void
    {
        $this->body = $body;
    }

    /**
     * Get body
     * @return string|null
     */
    public function getBody(): ?string
    {
        return $this->body;
    }
}
